package com.tsingtree.modular.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tsingtree.modular.entity.NanSellAnnounceBanner;
import com.tsingtree.modular.mapper.NanSellAnnounceBannerMapper;
import com.tsingtree.modular.model.params.NanSellAnnounceBannerParam;
import com.tsingtree.modular.service.NanSellAnnounceBannerService;
import com.tsingtree.roses.core.util.ToolUtil;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 社区Banner 服务实现类
 * </p>
 *
 * @author jagger
 * @since 2025-10-18
 */
@Service
public class NanSellAnnounceBannerServiceImpl extends ServiceImpl<NanSellAnnounceBannerMapper, NanSellAnnounceBanner> implements NanSellAnnounceBannerService {

    @Override
    public List<NanSellAnnounceBanner> findAllBanners() {
        return this.baseMapper.findAllBanners();
    }

    @Override
    public void add(NanSellAnnounceBannerParam param) {
        NanSellAnnounceBanner entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(NanSellAnnounceBannerParam param) {
        // 软删除
        NanSellAnnounceBanner entity = this.getById(getKey(param));
        if (entity != null) {
            entity.setIsDel(true);
            this.updateById(entity);
        }
    }

    @Override
    public NanSellAnnounceBanner findById(NanSellAnnounceBannerParam param) {
        return this.getById(getKey(param));
    }

    private Serializable getKey(NanSellAnnounceBannerParam param) {
        return param.getId();
    }

    private NanSellAnnounceBanner getEntity(NanSellAnnounceBannerParam param) {
        NanSellAnnounceBanner entity = new NanSellAnnounceBanner();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
